
import axios from 'axios'
//获取搜索建议
export const getSearchRecom = flag => {
    return axios.get(`/search/suggest?keywords=${flag}&type=mobile`)
}
// 获取综合搜索结果（mv,歌手）
export const getmultimatch = flag => {
    return axios.get(`/search/multimatch?keywords=${flag}`)
}
// 获取热门搜索列表
export const get_search_hotList = () => {
    return axios.get(`/search/hot`)
}
// 获取搜索结果
export const get_search_result = keyWord => {
    return axios.get(`/search?keywords=${keyWord}`)
}

// 获取搜索历史
export const get_song_history = () => {
    return JSON.parse(window.localStorage.getItem('songList'))
}
// 设置localstorage搜索历史
export const set_song_history = array =>{
    return window.localStorage.setItem('songList',JSON.stringify(array))
}
//
export const clear_song_history = () =>{
    localStorage.removeItem('songList');
}
// 将搜索结果添加到localstorage中
export const add_search_history = array => {
    var songList = get_song_history() || [];
    var index = songList.indexOf(array);
    if (index != -1) {
        songList.splice(index, 1);
    }else if(songList.length>=10){
        songList.splice(songList.length-1,1)
    }
    songList.unshift(array);
    return set_song_history(songList);
}